﻿using System;
using System.ComponentModel;
using DataStore.Domain;
using DataStore.Repositories;
using Microsoft.Practices.Composite.Events;

namespace Infrastructure.ViewModels
{
    /// <summary>
    /// Country viewmodel
    /// </summary>
    public class CountryViewModel : DataModelSingle<Country>, IDataErrorInfo
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="CountryViewModel"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="country">The country.</param>
        public CountryViewModel(IEventAggregator eventAggregator, Country country) : base(eventAggregator, country)
        {
           
            State = ModelState.Active;
        }

        /// <summary>
        /// Gets the country.
        /// </summary>
        /// <value>The country.</value>
        public Country Country
        {
            get
            {
                return Item;
            }
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public virtual Guid Id
        {
            get
            {
                return Item.Id;
            }
            set
            {
                Item.Id = value;
                OnPropertyChanged("Id");
            }
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public virtual string Name
        {
            get
            {
                return Item.Name;
            }
            set
            {
                if(Item.Name != value)
                {
                    Item.Name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        /// <summary>
        /// Gets or sets the language.
        /// </summary>
        /// <value>The language.</value>
        public virtual Language Language
        {
            get
            {
                return Item.Language;
            }
            set
            {
                if(Item.Language != value)
                {
                    Item.Language = value;
                    OnPropertyChanged("Language");
                }
            }
        }

        /// <summary>
        /// Gets or sets the flag.
        /// </summary>
        /// <value>The flag.</value>
        public virtual Link Flag
        {
            get
            {
                return Item.Flag;
            }
            set
            {
                if(Item.Flag != value)
                {
                    Item.Flag = value;
                    OnPropertyChanged("Flag");
                }
            }
        }

        #region IDataErrorInfo Members

        public string Error
        {
            get { throw new NotImplementedException(); }
        }

        public string this[string columnName]
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return Name;
        }
    }
}